﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BlackHole.DAO;

namespace BlackHole
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            //fill district list
            comboDistricts.Items.Clear();
            foreach (District d in Utility.GetAllDistricts())
            {
                comboDistricts.Items.Add(new ListItem(d.DistrictName,d.Id.ToString()));
            }
            //fill device list
            foreach (Device d in Utility.GetAllDevices())
            {
                comboDevices.Items.Add(new ListItem(d.DeviceName, d.Id.ToString()));
            }
            //fill product status
            radioStatus.Items.Clear();
            foreach (Utility.ProductStatus s in Enum.GetValues(typeof(Utility.ProductStatus)))
            {

                radioStatus.Items.Add(new ListItem(s.ToString(),((int)s).ToString()));
            }
            //set default datasource
            dataProducts.DataSource = sourceGetProductBySerial;
        }

        protected void comboDistricts_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboOwners.Items.Clear();
            foreach (Owner o in Utility.GetOwnersByDistrictId(int.Parse(comboDistricts.SelectedValue)))
            {
                comboOwners.Items.Add(new ListItem(o.OwnerName, o.Id.ToString()));
            }
        }


        protected void btnSerialClear_Click(object sender, EventArgs e)
        {
            txtSearchSerial.Text = string.Empty;
        }
    }
}